﻿<%@ Page Title="设置/修改维度-首家汽车行业人才测评系统" Language="C#" MasterPageFile="~/System/SiteSystem.Master"
    AutoEventWireup="true" CodeBehind="DimensionSet.aspx.cs" Inherits="EvaluationSystem.DimensionSet" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function Check() {
            var inputs = document.getElementsByTagName("input");
            if (inputs != null) {
                var sum = 0.0;
                for (var i = 0; i < inputs.length; i++) {
                    if (inputs[i].type == "text" && inputs[i].value != "") {
                        sum = sum + parseFloat(inputs[i].value);
                    }
                }
                var sum45 = adv_format(sum, 2);
                if (sum45 != 1.00) {
                    alert("请确认所选维度的权重总和为1");
                    return false;
                }
                else {
                    return true;
                }
            }
        }

        //对所有维度赋予相同权重
        function SetSameVal() {
            var sum = 0;
            var inputs = document.getElementsByTagName("input");
            if (inputs != null) {
                //计算总个数
                for (var i = 0; i < inputs.length; i++) {
                    if (inputs[i].type == "checkbox" && inputs[i].checked == true) {
                        sum++;
                    }
                }

                sum = sum - 3; //去除三个必选维度
                var total = 1.0;

                //开始平分
                for (var i = 11; i < inputs.length; i++) {
                    if (inputs[i].type == "checkbox" && inputs[i].checked == true) {
                        if (inputs[i + 1] && inputs[i+1].type == "text") {
                            inputs[i + 1].value = total / sum;
                        }
                    }

                    if (inputs[i].type == "checkbox" && inputs[i].checked == false) {
                        if (inputs[i + 1] && inputs[i + 1].type == "text") {
                            inputs[i + 1].value = "";
                        }
                    }

                }
            }
            return false;
        }

        //浮点数直接截位函数
        function formatnumber(value, num) {
            var tmp, idx, len, i
            tmp = value.toString();
            idx = tmp.indexOf('.');
            len = tmp.length;
            if (num == 0) {
                if (idx != -1)
                    tmp = tmp.substring(0, idx);
            }
            else {
                if (idx == -1) {
                    tmp = tmp + ".";
                    for (i = 1; i <= num; i++)
                        tmp = tmp + "0";
                } else {
                    tmp = tmp.substring(0, idx + num + 1);
                    for (i = len; i <= idx + num; i++)
                        tmp = tmp + "0";
                }
            }
            return tmp
        }

        //截位带四舍五入
        function adv_format(value, num) {
            var a_str = formatnumber(value, num);
            var a_int = parseFloat(a_str);
            if (value.toString().length > a_str.length) {
                var b_str = value.toString().substring(a_str.length, a_str.length + 1)
                var b_int = parseFloat(b_str);
                if (b_int < 5) {
                    return a_str
                } else {
                    var bonus_str, bonus_int;
                    if (num == 0) {
                        bonus_int = 1;
                    } else {
                        bonus_str = "0."
                        for (var i = 1; i < num; i++)
                            bonus_str += "0";
                        bonus_str += "1";
                        bonus_int = parseFloat(bonus_str);
                    }
                    a_str = formatnumber(a_int + bonus_int, num)
                }
            }
            return a_str
        }
 </script>
    <p>
        <asp:Label ID="lblSpec" runat="server" Width="550px"></asp:Label>
    </p>
    <asp:GridView ID="grVDimensionSet" runat="server" AutoGenerateColumns="False" CellPadding="4"
        DataKeyNames="dimension_id" ForeColor="#333333" GridLines="None" Width="100%"
        OnRowDataBound="GridView1_RowDataBound" EnableViewState="true" PageSize="10"
        HorizontalAlign="Center" OnPageIndexChanging="GridView1_IndexChanging">
        <FooterStyle BackColor="#63C1CD" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:TemplateField HeaderText="选择">
                <ItemTemplate>
                    <asp:CheckBox ID="CB_Select" runat="server" AutoPostBack="false" />
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="5%" Wrap="False" />
            </asp:TemplateField>
            <asp:BoundField DataField="dimension_id" HeaderText="维度ID" ReadOnly="True" SortExpression="dimension_id"
                Visible="false" />
            <asp:BoundField DataField="dimension_name" HeaderText="维度名称" SortExpression="dimension_name">
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="20%" Wrap="False" />
            </asp:BoundField>
            <asp:BoundField DataField="dimension_description" HeaderText="维度描述" SortExpression="dimension_description"
                Visible="false">
                <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="50%" Wrap="False" />
            </asp:BoundField>
            <asp:BoundField DataField="dimension_class_nm" HeaderText="维度类别" SortExpression="dimension_class_nm"
                Visible="false">
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="25%" Wrap="False" />
            </asp:BoundField>
            <asp:TemplateField Visible="false" HeaderText="权重">
                <ItemTemplate>
                    <asp:TextBox ID="txtbEdit" runat="server" CssClass="input" OnKeyPress="if(((event.keyCode>=48)&&(event.keyCode <=57))||(event.keyCode==46)) {event.returnValue=true;} else{event.returnValue=false;}"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <EmptyDataTemplate>
            对不起，没有当前的查询记录存在!
        </EmptyDataTemplate>
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#63C1CD" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <asp:CheckBox ID="CB_SelectAll" runat="server" AutoPostBack="true" OnCheckedChanged="CB_SelectAll_CheckedChanged"
        Text="全选" />
    <asp:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click" class="bluebtn" />
    <input type=button value="取消" onclick="history.back(-1)" />
    <asp:Button ID="btnSetSameVal" runat="server" Text="对所选维度赋予相同权重" 
        onclick="btnSetSameVal_Click" />
    <asp:Label ID="lblNotice" runat="server" Text="提醒：维度权重总和为1" Style="color: #FF6600"></asp:Label>
</asp:Content>
